package com.skytech.tax.customsdatawarehouse.singlewindow.processtrade.manual.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.processtrade.manual.domain.entity.ManualGoodsCon;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Lianhong
 * @since 2021/11/11
 */
@Repository
public class ManualGoodsConDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private String deleteManualGoodsConSql = "DELETE FROM sw_manual_goods_con WHERE seqNo=:seqNo and gseqNo in (:gseqNos)";

    public void removeBySeqNoAndGseqNoIn(String seqNo, List<String> gseqNos) {
        Map<String, Object> params = new HashMap<>();
        params.put("seqNo", seqNo);
        params.put("gseqNos", gseqNos);
        namedParameterJdbcTemplate.update(this.deleteManualGoodsConSql, params);
    }

    private String insertManualGoodsConSql = "INSERT INTO sw_manual_goods_con (seqNo, gseqNo, con, storageTime)" +
            " VALUES (:seqNo, :gseqNo, :con, :storageTime)";

    public void save(List<ManualGoodsCon> conList) {
        SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(conList);
        namedParameterJdbcTemplate.batchUpdate(insertManualGoodsConSql, batch);
    }
}


